#ifndef SCENEMODEL_H_
#define SCENEMODEL_H_

#include "model.h"
#include <list>
#include "objects/sceneObject.h"
#include "cube.h"
#include "model/actions/gravity.h"
#include "objects/ground.h"
#include "objects/clamp.h"
#include "objects/helicopter.h"
#include "objects/rain.h"
#include "objects/skyBox.h"
#include "objects/truck.h"
#include "light.h"
#include "watcher.h"

class SceneModelException: public std::exception{
private:
	std::string message;

	virtual const char* what()const throw(){
		return message.c_str();
	}
public:

	SceneModelException(const std::string& error) : message(error){}
	virtual ~SceneModelException()throw(){}
};


class SceneModel : public Model {
	public:
		typedef enum { DAY_ENVIRON,SUNSET_ENVIRON,NIGHT_ENVIRON,STORM_ENVIRON,MNT_ENVIRON,NO_ENVIRON } EnvironState;
	private:
		static const std::string modelPath;

		std::map<EnvironState,std::vector<Light*> > lights;
		std::vector<SceneObject*> objectList;
		std::map<std::string,unsigned int> indices;

		EnvironState currentEnvironState;
		Clamp* clamp;
		Helicopter* helicopter;
		Gravity gravity;
		Rain* rain;
		Truck* truck;
		SkyBox* sbox;
		Ground* ground;

		Cube sceneCube;
		Watcher watcher;
	public:
		SceneModel();
		virtual ~SceneModel();

		void timer(int value);
		void handleClamp();

		Helicopter& getHelicopter();
		Rain& getRain();
		SkyBox& getSkyBox();
		Cube& getSceneCube();
		Watcher& getWatcher();
		Truck& getTruck();
		Ground& getGround();

		const std::vector<SceneObject*>& getObjects()const{ return objectList; }

		EnvironState getEnvironState(){ return currentEnvironState; }
		void setEnviron(EnvironState state);

		const std::vector<Light*>& getEnvironLights(EnvironState state){ return lights[state]; }
	private:
		void clearObjects();
		void limitHelicopter();
		void initSceneObjects();

		void createCrates();
		void createHelicopter();
		void createTruck();
		void createSkyBox();
		void createGround();
		void createTrees();
		void createRain();
		void createPlatform();
		void createWarehouse();
		void createLightPosts();
		void createEnvironLights();

		void parsePathFile(Path& path,const std::string& fname,TruckPathInfo* &loadPathInfo,TruckPathInfo* &unloadPathInfo);
		void parseDistFile(const std::string& path,std::vector<Point>& points);
};

#endif /* SCENEMODEL_H_ */
